﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SmartMD.DataModel.Entity;
using System.Collections.ObjectModel;
using System.ComponentModel;
using SmartMD.DataAccess.Service;
using Techstar.Dialog;
using SmartMD.Manager.Utils;

namespace SmartMD.Manager.Patient
{
    /// <summary>
    /// Interaction logic for PatientInfoList.xaml
    /// </summary>
    public partial class PatientInfoList : BasePad
    {
        public StoreInfoPanel Owner { get; set; }
        private ObservableCollection<PatientInfo> _patientInfos;
        public ObservableCollection<PatientInfo> patientInfos
        {
            get
            {
                return _patientInfos;
            }
            set
            {
                _patientInfos = value;
                ICollectionView view = CollectionViewSource.GetDefaultView(value);
                PatientList.ItemsSource = view;
            }
        }

        public PatientInfoList()
        {
            InitializeComponent();
           /* patientInfos = DataServiceManager.PatientInfoService.loadAllPatientInfos();//new ObservableCollection<PatientInfo>();          
            ICollectionView view = CollectionViewSource.GetDefaultView(patientInfos);

            PatientList.ItemsSource = view;*/
        }

        private void BtnSearch_Click(object sender, RoutedEventArgs e)
        {
            ObservableCollection<PatientInfo> pInfos = SearchUtil.ForPatientInfos(TxtSearch.Text);
            if (pInfos == null)
            {
                TaskDialogEx.Warning("提示信息", "未查到您所要的患者信息！");
              //  this.TxtSearch.Text = "";
            }
            this.patientInfos = pInfos;
        }

        private void TxtSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                BtnSearch_Click(null, null);
        }

        private void PatientList_PreviewMouseMove(object sender, MouseEventArgs e)
        {

        }

        private void PatientList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.PatientList.SelectedItem == null)
                return;
            this.Owner.ucPatientInfoEdit.DataSource = (PatientInfo)this.PatientList.SelectedItem;
        }
        public void SetDeleteFlag()
        {
            if (this.PatientList.SelectedItem == null)
            {
                TaskDialogEx.Information("请选择要删除的项！");
                return;
            }
            PatientInfo item = (PatientInfo)this.PatientList.SelectedItem;
            item.State = DataModel.RecordState.Deleted;
        }
        public void Delete()
        {
            for (int j = 0; j < this.patientInfos.Count; j++)
            {
                if (this.patientInfos[j].State == DataModel.RecordState.Deleted)
                {
                    this.patientInfos.RemoveAt(j);
                }
            }
        }
    }
}
